<?php

class home_model extends MY_Model {

    protected $table = 'home';

    function __construct() {
        parent::__construct();
    }

    /**
     * 列表过滤
     */
    public function list_filter($config = array()) {
        /* 配置默认值设置 */
        $default_config = array(
            'select' => '*',
            'sort' => 'new',
            'get_all' => 0,
        );
        /* /配置默认值设置 */
        $config = array_merge($default_config, $config);

        $this->db->select($config['select']);
        return $config;
    }


    /**
     * 获取信息
     */
    public function get_home_by_site_id($site_id)
    {
        $this->db->where('site_id', $site_id);
        $row = $this->db->get($this->table)->row_array();
        return $row;
    }
    
    public function count_user($config = array(), $is_index = '', $status = 1) {
        $this->user_list_filter($config);

        return $this->db->count_all_results($this->table);
    }

    public function insert($data) {
        $this->db->insert($this->table, $data);
        return $this->db->insert_id();
    }

    public function update($site_id, $data) {
        $this->db->where('site_id', $site_id);

        return $this->db->update($this->table, $data);
    }

    public function del($user_id) {
        return $this->db->delete($this->table, array('user_id' => $user_id));
    }


}
